using System.Web;


namespace  Source.Web.FrameWork
{
    public interface INavigator
    {

        void GoTo(string url);
        string GetIncomingParameterValue(string key);
        
        int GetIncomingParameterAsInteger(string key);
        int? GetIncomingParameterAsNullableInteger(string key);
        
    }

    public class Navigator : INavigator
    {
        public virtual void GoTo(string url)
        {
            HttpContext.Current.Response.Redirect(url);
        }

        public virtual string GetIncomingParameterValue(string key)
        {
            return HttpContext.Current.Request.QueryString.Get(key);
        }

        public virtual int GetIncomingParameterAsInteger(string key)
        {
            string valueAsString = GetIncomingParameterValue(key);
            return int.Parse(valueAsString);
        }

        public virtual int? GetIncomingParameterAsNullableInteger(string key)
        {
            string valueAsString = GetIncomingParameterValue(key);

            if(valueAsString == null)
            {
                return null;
            }

            return int.Parse(valueAsString);
        }

    }
}